<?php
declare (strict_types=1);

namespace Plugin\File\Model;

use Mine\MineModel;

class RdFileVoice extends MineModel
{
    /**
     * The table associated with the model.
     *
     * @var string|null
     */
    protected ?string $table = 'rd_file_voice';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected array $fillable = [
        'id', 'file', 'text', 'type', 'created_at', 'updated_at'
    ];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected array $casts = [
        'id' => 'integer',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'type' => 'integer',
    ];

    // 音频类型常量
    const TYPE_CAMERA_NAME = 1;     // 摄像头名称
    const TYPE_ALARM_EVENT = 2;     // 预警事件
    const TYPE_COMPLIANCE_TEXT = 3; // 遵守文本

    /**
     * 被哪些报警类型引用
     */
    public function alarmTypes()
    {
        return $this->hasMany(\Plugin\Alarm\Model\RdAlarmHkType::class, 'voice_id');
    }
    
    /**
     * 获取音频类型标签
     * @return string
     */
    public function getTypeLabelAttribute(): string
    {
        $types = [
            self::TYPE_CAMERA_NAME => '摄像头名称',
            self::TYPE_ALARM_EVENT => '预警事件',
            self::TYPE_COMPLIANCE_TEXT => '遵守文本',
        ];
        
        return $types[$this->type] ?? '未知类型';
    }

    
}